package cn.lcl.ssh.web.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 全局拦截器，
 * Created by licho on 2017/9/26 0026.
 */
public class GlobalMessageInterceptor implements Interceptor{
    private static final Logger  log= Logger.getLogger(GlobalMessageInterceptor.class);
    @Override
    public void destroy() {
        log.debug("拦截器销毁了");
    }

    @Override
    public void init() {
        log.debug("拦截器启动了");
    }

    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {

        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("_root",request.getContextPath());
        String result=actionInvocation.invoke();
        log.debug("我拦截了请求："+request.getServletPath());
        return result;
    }
}
